<template>
  <!-- 顶部导航条 -->
  <header>
    <div class="hearderbox">
      <!-- 折叠图标 -->
      <div class="foldicon">
        <i :class="foldClass" @click="taggleFoldClass"></i>
      </div>
      <!-- 项目名称 -->
      <div class="projectName">
        <router-link to="/">
          <el-button type="text" class="exittxt">商城后台管理系统</el-button>
        </router-link>
      </div>
    </div>
    <div class="top-right-eleme">
      <span class="username">欢迎您：{{ loginUserName }}</span>
      <el-button type="text" class="exittxt" @click="exitLogin">退出</el-button>
    </div>
  </header>
</template>
<script>
import api from "../util/api";
// 引入微信sdk
import cloudbase from "@cloudbase/js-sdk";
// 初始化SDK
const app = cloudbase.init({
  env: api.envid,
});
// 登录时效，用户显式退出或更改密码之前的30天一直有效
const auth = app.auth({
  persistence: "local",
});

export default {
  data() {
    return {
      loginUserName: "",
      foldClass: "el-icon-s-fold",
    };
  },
  mounted() {
    this.loginUserName = this.cookie.getCookie("name");
  },
  methods: {
    exitLogin() {
      auth.signOut();      
      this.$router.replace({path: '/login'});
    },
    // 切换图标
    taggleFoldClass() {
      if (this.foldClass === "el-icon-s-fold") {
        this.foldClass = "el-icon-s-unfold";
        this.$emit("shrink", "indent");
      } else {
        this.foldClass = "el-icon-s-fold";
        this.$emit("shrink", "open");
      }
    },
  },
};
</script>
<style>
.hearderbox {  
  position: relative;
}
.foldicon {
  position: absolute;
  padding: 1px;
}
.projectName {
  position: absolute;
  left: 35px;
}
header {
  position: fixed;
  width: 100vw;
  height: 50px;
  line-height: 50px;
  left: 0;
  top: 0;
  background-color: #242424;
  color: #fff;
  padding-left: 1em;
}
.top-right-eleme {
  position: fixed;
  right: 20px;
  top: 0;
}
.exittxt {
  color: #fff !important;
}
.username {
  margin-right: 3em;
}
</style>
